<template>
  <div id="home">
    <div class="banner">
      <!-- 顶部搜索栏 -->
      <div class="search-box am-flexbox">
        <div class="search am-flexbox">
          <div class="location" @click="city">
            <span class="name">上海</span>
            <van-icon name="arrow-down" size="12"></van-icon>
          </div>
          <div class="form">
            <van-icon name="search"></van-icon>
            <input placeholder="请输入小区或地址" />
          </div>
        </div>
        <van-icon name="location-o" size="22px" color="white"></van-icon>
      </div>
      <!-- 轮播图 -->
      <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
        <van-swipe-item v-for="(item, index) in images" :key="index">
          <img :src="url + item.imgSrc" alt="" />
        </van-swipe-item>
      </van-swipe>
    </div>
    <!-- 功能模块 -->
    <div class="nav">
      <van-grid clickable :border="false" :column-num="4">
        <van-grid-item icon="home-o" text="整租" to="/find" />
        <!-- <van-icon /> -->
        <van-grid-item icon="friends-o" text="合租" to="/find" />
        <van-grid-item icon="search" text="地图找房" to="/" />
        <van-grid-item icon="shop-o" text="去出租" to="/find" />
      </van-grid>
    </div>
    <!-- 租房小组 -->
    <div class="group">
      <div class="title">
        <h4>租房小组</h4>
        <span>更多</span>
      </div>
      <div class="content">
        <div class="group-item" v-for="item in groupArr" :key="item.id">
          <div class="left">
            <p>{{ item.title }}</p>
            <span>{{ item.desc }}</span>
          </div>
          <div class="right">
            <img :src="url + item.imgSrc" alt="" />
          </div>
        </div>
      </div>
    </div>
    <!-- 最新资讯 -->
    <div class="news">
      <h3 class="group-title">最新资讯</h3>
      <div class="news-content">
        <div class="news-item" v-for="item in newsArr" :key="item.id">
          <div class="left">
            <img :src="url + item.imgSrc" alt="" />
          </div>
          <div class="right">
            <h3 class="title">{{ item.title }}</h3>
            <div class="info">
              <span>{{ item.from }}</span>
              <span>{{ item.date }}</span>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { groupApi, newsApi, swiperApi } from '@/api/home'
export default {
  name: 'UserPage',
  data () {
    return {
      value: '',
      images: [],
      groupArr: [],
      newsArr: [],
      url: 'http://www.xiaoshuaipeng.com:8080'
    }
  },
  async created () {
    // 轮播图
    const res = await swiperApi()
    this.images = res.data.body
    // 租房小组
    const res1 = await groupApi()
    this.groupArr = res1.data.body
    // 咨询
    const res2 = await newsApi()
    this.newsArr = res2.data.body
    console.log('首页创建了')
  },
  methods: {
    onSearch () {},
    city () {
      this.$router.push('/city')
    }
  },
  destroyed () {
    console.log('首页销毁了')
  }
}
</script>

<style lang="less" scoped>
#home {
  background-color: #f6f5f6;
}
.van-search__action {
  line-height: 20px;
}
.my-swipe {
  //轮播图
  height: 212px;
  .van-swipe-item {
    color: #fff;
    font-size: 20px;
    line-height: 150px;
    text-align: center;
    // background-color: #39a9ed;
    img {
      width: 100%;
      height: 100%;
    }
  }
}
.banner {
  position: relative;
  .search-box {
    //搜索
    // position: absolute;
    // left: 20px;
    // top: 25px;
    // width: 355px;
    // padding: 0 10px;
    z-index: 99;
    position: absolute;
    top: 25px;
    width: 100%;
    padding: 0 10px;
    .location {
      .name {
        margin-right: 4px;
        font-size: 14px;
      }
    }
    .search {
      flex: 1 1;
      height: 34px;
      margin: 0 10px;
      padding: 5px 5px 5px 8px;
      border-radius: 3px;
      background-color: #fff;
      // .van-icon-location-o {}
      .form {
        border-left: solid 1px #e5e5e5;
        margin-left: 12px;
        line-height: 16px;
        input {
          border: 0;
          padding-left: 4px;
          font-size: 13px;
          color: #9c9fa1;
        }
        .van-icon {
          vertical-align: middle;
          padding: 0 2px 0 12px;
          color: #9c9fa1;
          font-size: 15px;
        }
      }
    }
  }
}
.am-flexbox {
  text-align: left;
  overflow: hidden;
  display: flex;
  align-items: center;
}
.group {
  padding: 0 10px;
  .title {
    display: flex;
    justify-content: space-between;
    align-content: center;
    padding: 15px 0;
    h4 {
      font-size: 15px;
      color: #333;
    }
    span {
      font-size: 1px;
      color: #787d82;
    }
  }
  .content {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    .group-item {
      width: 172px;
      height: 85px;
      margin-bottom: 10px;
      background-color: #fff;
      display: flex;
      justify-content: space-evenly;
      align-items: center;
      .left {
        p {
          font-size: 13px;
          color: #333;
          margin-bottom: 5px;
        }
        span {
          font-size: 12px;
          color: #999;
        }
      }
      .right {
        width: 55px;
        img {
          width: 100%;
        }
      }
    }
  }
}
.news {
  margin-bottom: 50px;
  padding: 10px;
  background-color: #fff;
  .group-title {
    margin: 10px 0 5px 10px;
    font-size: 15px;
    color: #333;
  }
  .news-content {
    margin: 8px;
    .news-item {
      height: 120px;
      padding: 15px 10px 15px 0;
      display: flex;
      justify-content: space-between;
      border-bottom: 1px solid #e5e5e5;
      .left {
        width: 120px;
        height: 90px;
        img {
          width: 120px;
          height: 90px;
        }
      }
      .right {
        display: flex;
        flex-direction: column; /* 将主轴方向设置为垂直方向 */
        height: 100%;
        justify-content: center;
        padding-left: 12px;
        .title {
          flex: 1;
          font-size: 14px;
          color: #333;
          margin-bottom: 15px;
        }
        .info {
          display: flex;
          justify-content: space-between;
          span {
            font-size: 12px;
            color: #9c9fa1;
          }
        }
      }
    }
  }
}
</style>
